import time

from hytest import *
from lib.func_name import *
from lib.button import *
from lib.share import *


class UI_B1001:
    ddt_cases = [
        {'name': 'UI-B1001', 'para': ''},
        {'name': 'UI-B1002', 'para': ''},
        {'name': 'UI-B1003', 'para': ''},
    ]

    def teardown(self):
        GSTORE['thomework_created'].clear(GSTORE['thomework_created'].loc_select_input)

        GSTORE['thomework_created'].click(GSTORE['thomework_created'].loc_select_button)

    def teststeps(self):
        # obj1 = GSTORE['thome']
        # obj2 = GSTORE['thomework_create']
        # obj3 = GSTORE['iframe_homework_create']
        obj4 = GSTORE['thomework_created']
        # obj5 = GSTORE['question_info']
        # obj6 = GSTORE['release_to_student']
        # obj7 = GSTORE['release']

        if self.name == 'UI-B1001':
            homework_name_input = GSTORE['test_homework_name']
        if self.name == 'UI-B1002':
            homework_name_input = GSTORE['test_homework_name'][-6:]
        if self.name == 'UI-B1003':
            homework_name_input = '找不到的作业'

        obj4.input(obj4.loc_select_input, homework_name_input)
        obj4.click(obj4.loc_select_button)

        # questions = obj4.locates(obj4.loc_created_question)
        question_name = obj4.get_txt_floor(xpath, obj4.created_homework_name, index1=1)['msg']

        if self.name == 'UI-B1001':
            CHECK_POINT('目标习题被筛选出来', question_name == GSTORE['test_homework_name'])
        if self.name == 'UI-B1002':
            CHECK_POINT('目标习题被筛选出来', GSTORE['test_homework_name'][-6] in question_name)
        if self.name == 'UI-B1003':
            CHECK_POINT('没有作业被筛选出来', question_name == 'floor text获取失败')


class UI_B2101:
    ddt_cases = [
        {'name': 'UI-B2101', 'para': ''},
        {'name': 'UI-B2202', 'para': ''},
    ]

    def teardown(self):
        GSTORE['thomework_created'].clear(GSTORE['thomework_created'].loc_select_input)
        GSTORE['thomework_created'].click(GSTORE['thomework_created'].loc_select_button)

    def teststeps(self):
        # obj1 = GSTORE['thome']
        # obj2 = GSTORE['thomework_create']
        # obj3 = GSTORE['iframe_homework_create']
        obj4 = GSTORE['thomework_created']
        obj5 = GSTORE['question_info']
        # obj6 = GSTORE['release_to_student']
        # obj7 = GSTORE['release']

        obj4.click_floor(xpath, obj4.button_created_check, index1=1)
        main_window = obj4.jump_window('试卷查看')
        desc = obj5.get_txt(obj5.loc_question_desc).strip()
        CHECK_POINT('查看作业与创建的作业信息一致', desc == GSTORE['test_homework_name'])
        obj5.driver.close()
        obj4.return_main_window(main_window)


class UI_B2201:
    ddt_cases = [
        {'name': 'UI-B2201', 'para': ''},
        {'name': 'UI-B2203', 'para': ''},
        {'name': 'UI-B2204', 'para': ''},
        {'name': 'UI-B2205', 'para': ''},
        {'name': 'UI-B2206', 'para': ''},
    ]

    def setup(self):
        GSTORE['thomework_created'].click_floor(xpath,
                                                GSTORE['thomework_created'].button_created_change,
                                                index1=1)

    def teardown(self):
        GSTORE['thomework_created'].open_homework_created()
        time.sleep(1)

    def teststeps(self):
        # obj1 = GSTORE['thome']
        # obj2 = GSTORE['thomework_create']
        # obj3 = GSTORE['iframe_homework_create']
        obj4 = GSTORE['thomework_created']
        # obj5 = GSTORE['question_info']
        # obj6 = GSTORE['release_to_student']
        # obj7 = GSTORE['release']

        if self.name == 'UI-B2201':
            page_title = obj4.get_txt(obj4.loc_homework_change_title)
            CHECK_POINT('进入编辑页面', page_title == '编辑作业')
        if self.name == 'UI-B2203':
            question_count1 = len(obj4.locates(obj4.loc_homework_change_qusetions))
            obj4.click_floor(xpath,
                             obj4.loc_homework_change_button_delete_value,
                             index1=1)
            question_count2 = len(obj4.locates(obj4.loc_homework_change_qusetions))
            check_count = question_count1 - question_count2
            INFO(question_count1)
            CHECK_POINT('所选试题被删除', check_count == 1)
        if self.name == 'UI-B2204':
            ques_content1 = obj4.question_change_page_get_question_info(2)
            obj4.click_floor(xpath, obj4.loc_homework_change_button_up_value, index1=2)
            time.sleep(0.5)
            ques_content2 = obj4.question_change_page_get_question_info(1)
            CHECK_POINT('题目上移', ques_content1 == ques_content2)
        if self.name == 'UI-B2205':
            ques_content1 = obj4.question_change_page_get_question_info(1)
            obj4.click_floor(xpath, obj4.loc_homework_change_button_down_value, index1=1)
            time.sleep(0.5)
            ques_content2 = obj4.question_change_page_get_question_info(2)
            INFO(ques_content1)
            INFO(ques_content2)
            CHECK_POINT('题目上移', ques_content1 == ques_content2)
        if self.name == 'UI-B2206':
            ques_content1_1 = obj4.question_change_page_get_question_info(1)
            ques_content1_2 = obj4.question_change_page_get_question_info(2)
            ques_content1_3 = obj4.question_change_page_get_question_info(3)
            ques_count1 = len(obj4.locates(obj4.loc_homework_change_qusetions))

            obj4.click_floor(xpath, obj4.loc_homework_change_button_down_value, index1=1)
            time.sleep(0.5)
            obj4.click_floor(xpath, obj4.loc_homework_change_button_up_value, index1=3)
            time.sleep(0.5)
            obj4.click_floor(xpath, obj4.loc_homework_change_button_delete_value, index1=4)
            time.sleep(0.5)

            ques_content2_1 = obj4.question_change_page_get_question_info(1)
            ques_content2_2 = obj4.question_change_page_get_question_info(2)
            ques_content2_3 = obj4.question_change_page_get_question_info(3)
            ques_count2 = len(obj4.locates(obj4.loc_homework_change_qusetions))

            CHECK_POINT('题目被正常编辑', ques_content1_1 == ques_content2_3 and
                                    ques_content1_2 == ques_content2_1 and
                                    ques_content1_3 == ques_content2_2 and
                                    ques_count1 - ques_count2 == 1)
